package com.jeomo.sys.starter.mapper;

import com.jeomo.base.starter.mapper.IBaseMapper;
import com.jeomo.sys.starter.entity.Dict;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import javax.validation.constraints.NotBlank;
import java.util.List;

@Mapper
public interface DictMapper extends IBaseMapper<Dict> {

    /**
     * 根据类型码和字典码来获取来获取
     * @param type
     * @param code
     * @return
     */
    @Select("select * from sys_dict where code = #{code} and type = #{type}")
    Dict queryByCode(@Param(value = "type") String type, @Param(value = "code") String code);

    /**
     * 根据类型码和字典码来获取来获取
     * @return
     */
    @Select("select distinct type from sys_dict")
    List<String> queryAllType();

    /**
     * 根据typeCode查询字典
     * @param type
     * @return
     */
    @Select("select * from sys_dict where type = #{type}")
    List<Dict> queryByTypeCode(@Param(value = "type")String type);

    /**
     * 删除
     * @param type
     * @param code
     * @return
     */
    @Delete("delete from sys_dict where type = #{type} and code = #{code}")
    int remove(@NotBlank @Param(value = "type") String type, @NotBlank @Param(value = "code") String code);

}
